# -- coding: utf-8 --
# @Time : 2022/7/18
# @Author : ykk648
# @Project : https://github.com/ykk648/AI_power
"""
kintree: kinematic tree
"""

BONE_CONFIG = {
    'mediapipe_body33': {
        # ref /mediapipe/python/solutions
        'nJoints': 33,
        'kintree': [[0, 1], [1, 2], [2, 3], [3, 7], [0, 4], [4, 5],
                    [5, 6], [6, 8], [9, 10], [11, 12], [11, 13],
                    [13, 15], [15, 17], [15, 19], [15, 21], [17, 19],
                    [12, 14], [14, 16], [16, 18], [16, 20], [16, 22],
                    [18, 20], [11, 23], [12, 24], [23, 24], [23, 25],
                    [24, 26], [25, 27], [26, 28], [27, 29], [28, 30],
                    [29, 31], [30, 32], [27, 31], [28, 32]],
        'joint_names': ["Nose", "..", "LEye", "..", "..", "REye", "..", "LEar", "REar", "..", "..", "LShoulder",
                        "RShoulder",
                        "LElbow", "RElbow", "LWrist", "RWrist", "..", "..", "..", "..", "..", "..", "LHip", "RHip",
                        "LKnee", "RKnee", "LAnkle", "RAnkle",
                        "LHeel", "RHeel", "LSmallToe", "RSmallToe",
                        ]
    },
    'alphapose_17': {
        'nJoints': 17,
        'kintree': [],
        'joint_names': []
    },
    'openpose_body25': {
        'nJoints': 25,
        'kintree': [[1, 0], [2, 1], [3, 2], [4, 3], [5, 1], [6, 5],
                    [7, 6], [8, 1], [9, 8], [10, 9], [11, 10], [12, 8],
                    [13, 12], [14, 13], [15, 0], [16, 0], [17, 15], [18, 16],
                    [19, 14], [20, 19], [21, 14], [22, 11], [23, 22], [24, 11]],
        'joint_names': ["Nose", "Neck", "RShoulder", "RElbow", "RWrist", "LShoulder", "LElbow",
                        "LWrist", "MidHip", "RHip", "RKnee", "RAnkle", "LHip", "LKnee", "LAnkle",
                        "REye", "LEye", "REar", "LEar", "LBigToe", "LSmallToe", "LHeel", "RBigToe",
                        "RSmallToe", "RHeel"]
    },
    'smpl_24': {
        'nJoints': 24,
        'kintree': [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6],
                    [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12],
                    [9, 13], [9, 14], [12, 15], [13, 16], [14, 17], [16, 18],
                    [17, 19], [18, 20], [19, 21], [20, 22], [21, 23], ],
        'joint_names': ['MidHip', 'LUpLeg', 'RUpLeg', 'spine', 'LLeg', 'RLeg', 'spine1', 'LFoot', 'RFoot', 'spine2',
                        'LToeBase', 'RToeBase', 'neck', 'LShoulder', 'RShoulder', 'head', 'LArm', 'RArm', 'LForeArm',
                        'RForeArm', 'LHand', 'RHand', 'LHandIndex1', 'RHandIndex1', ]
    },
    'openpose_bodyhand67': {
        'nJoints': 67,
        'kintree': [[1, 0], [2, 1], [3, 2], [4, 3], [5, 1], [6, 5],
                    [7, 6], [8, 1], [9, 8], [10, 9], [11, 10], [12, 8],
                    [13, 12], [14, 13], [15, 0], [16, 0], [17, 15], [18, 16],
                    [19, 14], [20, 19], [21, 14], [22, 11], [23, 22], [24, 11],
                    # handl
                    [26, 7], [27, 26], [28, 27], [29, 28], [30, 7], [31, 30], [32, 31],
                    [33, 32], [34, 7], [35, 34], [36, 35], [37, 36], [38, 7], [39, 38],
                    [40, 39], [41, 40], [42, 7], [43, 42], [44, 43], [45, 44],
                    # handr
                    [47, 4], [48, 47], [49, 48], [50, 49], [51, 4], [52, 51], [53, 52],
                    [54, 53], [55, 4], [56, 55], [57, 56], [58, 57], [59, 4], [60, 59],
                    [61, 60], [62, 61], [63, 4], [64, 63], [65, 64], [66, 65]],
        'skeleton': {
            (0, 1): {'mean': 0.251, 'std': 0.050},
            (1, 2): {'mean': 0.169, 'std': 0.034},
            (2, 3): {'mean': 0.292, 'std': 0.058},
            (3, 4): {'mean': 0.275, 'std': 0.055},
            (1, 5): {'mean': 0.169, 'std': 0.034},
            (5, 6): {'mean': 0.295, 'std': 0.059},
            (6, 7): {'mean': 0.278, 'std': 0.056},
            (1, 8): {'mean': 0.566, 'std': 0.113},
            (8, 9): {'mean': 0.110, 'std': 0.022},
            (9, 10): {'mean': 0.398, 'std': 0.080},
            (10, 11): {'mean': 0.402, 'std': 0.080},
            (8, 12): {'mean': 0.111, 'std': 0.022},
            (12, 13): {'mean': 0.395, 'std': 0.079},
            (13, 14): {'mean': 0.403, 'std': 0.081},
            (0, 15): {'mean': 0.053, 'std': 0.011},
            (0, 16): {'mean': 0.056, 'std': 0.011},
            (15, 17): {'mean': 0.107, 'std': 0.021},
            (16, 18): {'mean': 0.107, 'std': 0.021},
            (14, 19): {'mean': 0.180, 'std': 0.036},
            (19, 20): {'mean': 0.055, 'std': 0.011},
            (14, 21): {'mean': 0.065, 'std': 0.013},
            (11, 22): {'mean': 0.169, 'std': 0.034},
            (22, 23): {'mean': 0.052, 'std': 0.010},
            (11, 24): {'mean': 0.061, 'std': 0.012},
            (7, 26): {'mean': 0.045, 'std': 0.009},
            (26, 27): {'mean': 0.042, 'std': 0.008},
            (27, 28): {'mean': 0.035, 'std': 0.007},
            (28, 29): {'mean': 0.029, 'std': 0.006},
            (7, 30): {'mean': 0.102, 'std': 0.020},
            (30, 31): {'mean': 0.040, 'std': 0.008},
            (31, 32): {'mean': 0.026, 'std': 0.005},
            (32, 33): {'mean': 0.023, 'std': 0.005},
            (7, 34): {'mean': 0.101, 'std': 0.020},
            (34, 35): {'mean': 0.043, 'std': 0.009},
            (35, 36): {'mean': 0.029, 'std': 0.006},
            (36, 37): {'mean': 0.024, 'std': 0.005},
            (7, 38): {'mean': 0.097, 'std': 0.019},
            (38, 39): {'mean': 0.041, 'std': 0.008},
            (39, 40): {'mean': 0.027, 'std': 0.005},
            (40, 41): {'mean': 0.024, 'std': 0.005},
            (7, 42): {'mean': 0.095, 'std': 0.019},
            (42, 43): {'mean': 0.033, 'std': 0.007},
            (43, 44): {'mean': 0.020, 'std': 0.004},
            (44, 45): {'mean': 0.018, 'std': 0.004},
            (4, 47): {'mean': 0.043, 'std': 0.009},
            (47, 48): {'mean': 0.041, 'std': 0.008},
            (48, 49): {'mean': 0.034, 'std': 0.007},
            (49, 50): {'mean': 0.028, 'std': 0.006},
            (4, 51): {'mean': 0.101, 'std': 0.020},
            (51, 52): {'mean': 0.041, 'std': 0.008},
            (52, 53): {'mean': 0.026, 'std': 0.005},
            (53, 54): {'mean': 0.024, 'std': 0.005},
            (4, 55): {'mean': 0.100, 'std': 0.020},
            (55, 56): {'mean': 0.044, 'std': 0.009},
            (56, 57): {'mean': 0.029, 'std': 0.006},
            (57, 58): {'mean': 0.023, 'std': 0.005},
            (4, 59): {'mean': 0.096, 'std': 0.019},
            (59, 60): {'mean': 0.040, 'std': 0.008},
            (60, 61): {'mean': 0.028, 'std': 0.006},
            (61, 62): {'mean': 0.023, 'std': 0.005},
            (4, 63): {'mean': 0.094, 'std': 0.019},
            (63, 64): {'mean': 0.032, 'std': 0.006},
            (64, 65): {'mean': 0.020, 'std': 0.004},
            (65, 66): {'mean': 0.018, 'std': 0.004},
        }
    }
}

openpose_25_bone_links = [
    (0, 15), (0, 16), (15, 17), (16, 18),
    (0, 1), (1, 2), (2, 3), (3, 4), (1, 5), (5, 6), (6, 7), (1, 8),
    (8, 9), (9, 10), (10, 11), (11, 24), (11, 22), (22, 23),
    (8, 12), (12, 13), (13, 14), (14, 21), (14, 19), (19, 20)
]
